package com.mf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mf.entity.bo.WorkInfoBo;
import com.mf.entity.vo.WorkInfoVo;
import com.mf.mapper.WorkInfoMapper;

import com.mf.service.IWorkInfoService;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.github.heollhai.common.utils.MybatisPlusUtils;
import io.github.heollhai.common.utils.VerifyUtils;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务实现类
 *
 * @author mf
 * @since 2024-09-01
 */
@Service
public class WorkInfoServiceImpl extends ServiceImpl<WorkInfoMapper, WorkInfoBo> implements IWorkInfoService {
    @Resource
    private WorkInfoMapper workInfoMapper;


    /**
     * 查询
     */
    @Override
    public List<WorkInfoVo> listByRosterId(Integer rosterId) {
        final LambdaQueryWrapper<WorkInfoBo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(WorkInfoBo::getRosterId, rosterId);
        List<WorkInfoBo> workInfoBos = workInfoMapper.selectList(wrapper);
        return MybatisPlusUtils.changeDataClass(workInfoBos, WorkInfoVo.class);
    }

    /**
     * 新增|编辑
     */
    @Override
    public Integer insert(WorkInfoVo workInfoVo) {
        final WorkInfoBo workInfoBo = new WorkInfoBo();
        BeanUtils.copyProperties(workInfoVo, workInfoBo);
        if(VerifyUtils.isEmpty(workInfoVo.getId())){
            return workInfoMapper.insert(workInfoBo);
        }

        return  workInfoMapper.updateById(workInfoBo);
    }
}
